// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App'
import router from './router'

import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)

Vue.use(ElementUI);

Vue.prototype.baseUrl = process.env.API_ROOT

Vue.config.productionTip = false
axios.defaults.withCredentials = true;
/* eslint-disable no-new */
let vm = new Vue({
  el: '#app',
  router,
  components: {App},
  template: '<App/>'
})

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

axios.interceptors.response.use(data => {
  return data;
}, error => {
  let status = error.response.status;
  let route = vm.$route.query.route;
  let activeIndex =  vm.$route.query.activeIndex;
  let id = vm.$route.query.id;
  if (status === 403) {
    vm.$router.push({
      path: "/login",
      query: {
        route: route,
        activeIndex: activeIndex,
        id: id
      }
    })
  } else {
    vm.$message.error(error.response.data.msg)
  }
  return Promise.reject(error);
})
